package com.woniu.user.service.consumer;

import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.woniu.product.client.param.RestoreStockParam;
import com.woniu.user.infra.model.UserVipRelation;
import com.woniu.user.service.UserVipRelationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "lxlg-vip-order",topic = "lxlg-vip-order")
public class VipOrderConsumer implements RocketMQListener<Integer> {
    @Resource
    private UserVipRelationService userVipRelationService;
    @Override
    public void onMessage(Integer message) {
//        System.out.println("============三十分钟之后，没有支付取消订单=======================");
//        UserVipRelation userVipRelation= userVipRelationService.getById(message);
//        userVipRelation.setStatus("EXPIRE");
//        userVipRelationService.updateById(userVipRelation);

        log.info("============开始检查当前订单的支付情况===========");
        UserVipRelation byId = userVipRelationService.getById(message);
        if(byId.getStatus().equals("UNPAID")) {
            byId.setStatus("EXPIRE");
            userVipRelationService.updateById(byId);
            log.info("============退单执行结束===========");
        } else
            log.info("============发现订单已经支付，不做处理===========");
    }
}
